#include "Mutex.hpp"

using namespace MutexModel;

struct ThreadData
{
    std::string  name;
    Mutex* lock;
    ThreadData(std::string n,Mutex* l)
    :name(n),
    lock(l)
    {}

};
void* routine(void* args)
{
    ThreadData* td=static_cast<ThreadData*>(args);
    while(true)
    {
        LockGuard guard(*td->lock);//RAII守卫
        //.......



        //.......

    }
    return nullptr;
}
int main()
{
    Mutex mtx;
    pthread_t t1,t2;
    ThreadData* td1=new ThreadData("thread-1",&mtx);
    ThreadData* td2=new ThreadData("thread-2",&mtx);
    pthread_create(&t1,nullptr,routine,(void*)td1);
    pthread_create(&t1,nullptr,routine,(void*)td2);

    pthread_join(t1,nullptr);
    pthread_join(t2,nullptr);


    return 0;
}